Skip to main content

Multisearch

Description

<jp-multisearch> is a component with a combination of search and multi select functionalities.


Attributes

NameRequiredTypeDescription
valuestringsetter
serviceSearchServicesearch service
namestringname of the form control
minSelectsnumberminimum number of selects allowed
singleSelectbooleanis it possible to select only one option or more
minselectsValidationMessagestringvalidation message for when component does not satisfy minselects
maxSelectsnumbermaximum number of selects allowed
maxselectsValidationMessagestringvalidation message for when component does not satisfy maxselects
requiredbooleandetermines if a selection is required
requiredValidationMessagestringvalidation message for when component does not satisfy required
disabledbooleandetermines if a selection is disabled
idstringunique identifier
labelstringshows at the top of the field
labelType'outside' or 'inside'whether label is inside or outside of the field
hintstringshows below the field
validationMessages{[type]: string} where type is stringcompact way of writing validation messages in a single attribute
defaultSearchbooleandetermines if options are visible upon opening
defaultShowNumbernumberdetermines number of visible options


Interfaces

SearchService

Defines functions for getting select options.



Properties
NameRequiredTypeDescription
search(str: string) => Promise<Array<Option>>option results from search
getSingleif value is provided(str: string) => Promise<Array<Option>>returns option given the value
loadMore(str: string) => Promise<Array<Option>>returns options given current search string

Where Option is { label?: string; value: string; selected?: boolean; disabled?: boolean }



Slots

This component does not have any slots.



Methods

  • getValue
    • returns form field value
  • reportValidity
    • triggers reportValidity


Events

  • value
    • triggers when selected options change


Demo

Live Editor
// import '@jaspero/web-components/multisearch.wc.js';
// import '@jaspero/web-components/multisearch.css';

function multisearch(props) {
  let el = useRef(null);
  useEffect(() => {
    const multisearch = document.createElement('jp-multisearch');
    multisearch.value = 'aaa, bbb';
    multisearch.service = {
      i: 0,
      async search(str) {
        await new Promise((resolve) => setTimeout(resolve, 1500));
        return [{ value: 'str+1' }, { value: 'str+2' }];
      },
      async loadMore(str) {
        await new Promise((resolve) => setTimeout(resolve, 1500));
        this.loadMore = null;
        return [{ value: str }];
      },
      async getSingle(value) {
        await new Promise((resolve) => setTimeout(resolve, 1500));
        return { value: value, label: this.i++ };
      }
    };
    el.current.appendChild(multisearch);
  });
  return <div ref={el}></div>;
}
Result
Loading...